package com.gzhryc.shared_device.oem.code;

import com.gzhryc.common.StringTools;
import com.gzhryc.common.config.PropertyTools;
import com.gzhryc.common.logging.Logger;
import com.gzhryc.common.sms.SmsService;
import com.gzhryc.common.sms.TaobaoSmsHandler;

import org.apache.commons.lang3.time.DateUtils;

import java.text.ParseException;
import java.util.Date;

public class BaseConstants {

    static Logger log = Logger.getLogger(BaseConstants.class);

    public final static String VERSION = "V0.4.2";

    public final static String JDBC_KEY = "oem_jdbc_key";

    public static boolean getCDB(){
        return PropertyTools.get().getBoolean(  "cdb.enable", false);
    }

    public static boolean getCDCZ(){
        return PropertyTools.get().getBoolean(  "cdcz.enable", false);
    }

    public static boolean getBXSCN(){
        return PropertyTools.get().getBoolean(  "bxscn.enable", false);
    }

    public static boolean getPCL(){
        return PropertyTools.get().getBoolean(  "pcl.enable", false);
    }

    public static boolean getMarket(){
        return PropertyTools.get().getBoolean(  "market.enable", false);
    }
    
    public static boolean initalSMS() {
    	String keyId = PropertyTools.get().getString("sms_keyId");
    	String keySecret = PropertyTools.get().getString("sms_keySecret");
    	String templateCode = PropertyTools.get().getString("sms_templateCode");
    	if(StringTools.isNotBlank(keyId) && StringTools.isNotBlank(keySecret) && StringTools.isNotBlank(templateCode)) {
	    	SmsService.open(1, new TaobaoSmsHandler(keyId,keySecret, templateCode));
	    	return true;
    	}
    	return false;
    }

    private static Date startDate;
    public static Date getStartDate(){
        if(startDate == null){
            String startDateStr = PropertyTools.get().getString("startDate","2023-01");
            try {
                startDate = DateUtils.parseDate(startDateStr,"yyyy-MM");
            } catch (ParseException e) {
                log.error(e.getMessage(),e);
            }
        }
        return startDate;
    }

}
